package com.pine.dcts.auth.config;


import com.pine.app.module.security.core.authorize.metadataSource.AuthorizeProperties;
import com.pine.app.module.security.oauth.config.properties.LoginProperties;
import com.pine.app.module.security.oauth.plugin.impl.loginAttemp.RedisLoginAttempServiceImpl;
import com.pine.app.module.security.oauth.provider.authrizationCode.AuthenticationCodeStore;
import com.pine.app.module.security.oauth.provider.authrizationCode.RedisAuthenticationCodeStore;
import com.pine.app.module.security.oauth.provider.client.ClientDetailsService;
import com.pine.app.module.security.oauth.provider.client.dao.ClientDao;
import com.pine.app.module.security.oauth.provider.client.dao.impl.ClientDaoImpl;
import com.pine.app.module.security.oauth.provider.client.service.ClientService;
import com.pine.app.module.security.oauth.provider.client.service.impl.ClientServiceImpl;
import com.pine.app.module.security.oauth.provider.client.service.impl.DataBaseCacheClientDetailServiceImpl;
import com.pine.app.module.security.oauth.provider.token.store.RedisTokenStore;
import com.pine.app.module.security.oauth.provider.token.store.TokenStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import javax.sql.DataSource;

/**
 * @author xiaoyuan
 * @create 2020/3/20 1:01
 **/

@Configuration
public class WebSecurityConfig {


    private RedisTemplate redisTemplate;

    private DataSource dataSource;

    private AuthorizeProperties authorizeProperties;

    private LoginProperties loginProperties;

    public WebSecurityConfig(RedisTemplate redisTemplate,
                             DataSource dataSource,
                             LoginProperties loginProperties
                            ){
        this.redisTemplate = redisTemplate;
        this.dataSource = dataSource;
        this.loginProperties= loginProperties;

    }

    @Bean
    public ClientDao clientDao(){
        return new ClientDaoImpl(dataSource);
    }
    @Bean
    public ClientService clientService(){
        return new ClientServiceImpl();
    }
    @Bean
    public TokenStore tokenStore(){
        return new RedisTokenStore(redisTemplate);
    }

    @Bean
    public ClientDetailsService clientDetailsService(){
        return new DataBaseCacheClientDetailServiceImpl();
    }

    @Bean
    public AuthenticationCodeStore authenticationCodeStore(){
        return new RedisAuthenticationCodeStore(redisTemplate);
    }
    @Bean
    public RedisLoginAttempServiceImpl redisLoginAttempService(){
        return new RedisLoginAttempServiceImpl(redisTemplate,loginProperties);
    }



}
